package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.entity.Group;
import com.burgeon.backend.SHOP.entity.GroupItem;
import com.burgeon.backend.SHOP.entity.GroupVO;
import com.burgeon.backend.SHOP.service.GroupService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("shop/group")
public class GroupController extends BaseController{

    @Autowired
    private GroupService groupService;

    @RequestMapping("showImg")
    public ResponseResult<String> showImg(HttpSession session){
        String token = session.getAttribute("token").toString();
        String data = groupService.showImg(token);
        return new ResponseResult<String>(SUCCESS,data);
    }

    @RequestMapping("showGroupById")
    public ResponseResult<List<GroupItem>> showGroupById(String id){
        List<GroupItem> data = groupService.getGroupItem(id);
        return new ResponseResult<List<GroupItem>>(SUCCESS,data);
    }

    @RequestMapping("showGoodsGroupList")
    public ResponseResult<HashMap> showGoodsGroupList(String gid,HttpSession session){
        String uid = "null";//未登录用户
        if (null != session.getAttribute("uid")) {
            uid = session.getAttribute("uid").toString();
        }
        HashMap data = groupService.getGoodsGroupList(gid,uid);
        return new ResponseResult<HashMap>(SUCCESS,data);
    }

    @RequestMapping("showGroup")
    public ResponseResult<List<Group>> showGroup(HttpSession session){
        String token = session.getAttribute("token").toString();
        List<Group> data = groupService.showGroup(token);
        return new ResponseResult<List<Group>>(SUCCESS,data);
    }

}
